package com.jubaozan.feign.platform;

import com.jubaozan.c3.framework.constants.Constants;
import com.jubaozan.c3.framework.utils.ResultHolder;
import com.jubaozan.feign.platform.vo.StockLockVO;
import com.jubaozan.feign.platform.vo.StockVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author c3
 */
@ApiIgnore
@FeignClient(name = "stock-service")
public interface StockFeignService {
    @ApiOperation("创建库存")
    @PostMapping("")
    ResultHolder<StockVO> save(@RequestParam("quantity") Long quantity,
                               @RequestHeader(Constants.KEY_X_C3_TENANTID) Long tenantId,
                               @RequestHeader(Constants.KEY_X_C3_PLATFORM) String platform,
                               @RequestParam("echo") String echo);

    @ApiOperation("批量创建库存")
    @PostMapping("/batch")
    ResultHolder<List<StockVO>> batchSave(@RequestBody List<StockVO> stockList,
                                          @RequestHeader(Constants.KEY_X_C3_TENANTID) Long tenantId,
                                          @RequestHeader(Constants.KEY_X_C3_PLATFORM) String platform);
    @ApiOperation("批量创建/更新库存")
    @PatchMapping("/batch")
    ResultHolder<List<StockVO>> batchSaveOrUpdate(@RequestBody List<StockVO> stockList,
                                                  @RequestHeader(Constants.KEY_X_C3_TENANTID) Long tenantId,
                                                  @RequestHeader(Constants.KEY_X_C3_PLATFORM) String platform);

    @ApiOperation("锁定库存")
    @PostMapping("/lock")
    ResultHolder<StockLockVO> lock(@RequestParam("lockId") Long stockId,
                                   @RequestParam("lockQuantity") Long lockQuantity,
                                   @RequestParam("timeout") Long timeout);

    @ApiOperation("批量锁定库存")
    @PostMapping("/lock/batch")
    ResultHolder<List<StockLockVO>> batchLock(@RequestBody List<StockLockVO> stockList);

    @ApiOperation("增加库存")
    @PostMapping("/add")
    ResultHolder<StockVO> add(@RequestParam("stockId") Long stockId,
                              @RequestParam("quantity") Long quantity,
                              @RequestHeader(Constants.KEY_X_C3_USERNAME) String username);

    @ApiOperation("批量增加库存")
    @PostMapping("/add/batch")
    ResultHolder<List<StockVO>> batchAdd(@RequestBody List<StockVO> stockAdds,
                                         @RequestHeader(Constants.KEY_X_C3_USERNAME) String username);

    @ApiOperation("退还库存")
    @PutMapping("/back")
    ResultHolder<StockVO> back(@RequestParam("lockId") Long lockId);

    @ApiOperation("批量退还")
    @PutMapping("/back/batch")
    ResultHolder<List<StockVO>> batchBack(@RequestBody List<Long> lockIds);

    @ApiOperation("扣库存")
    @PutMapping("/confirm")
    ResultHolder<StockVO> confirm(@RequestParam("lockId") Long lockId);

    @ApiOperation("批量扣库存")
    @PutMapping("/confirm/batch")
    ResultHolder<List<StockVO>> batchConfirm(@RequestBody List<Long> lockIds);

    @ApiOperation("查询库存")
    @GetMapping("")
    ResultHolder<StockVO> query(@RequestParam("stockId") Long stockId);

    @ApiOperation("批量查询库存")
    @GetMapping("/batch")
    ResultHolder<List<StockVO>> batchQuery(@RequestParam List<Long> stockIds);

    @ApiOperation("更新库存")
    @PutMapping("")
    ResultHolder<StockVO> update(@RequestParam("stockId") Long stockId,
                                 @RequestParam("quantity") Long quantity,
                                 @RequestHeader(Constants.KEY_X_C3_USERNAME) String username);

    @ApiOperation("批量更新库存")
    @PutMapping("/batch")
    ResultHolder<List<StockVO>> batchUpdate(@RequestBody List<StockVO> stockList,
                                            @RequestHeader(Constants.KEY_X_C3_USERNAME) String username);


    @ApiOperation("订阅库存")
    @PostMapping("/subscribe")
    ResultHolder<?> subscribe(@RequestHeader(Constants.KEY_X_C3_TENANTID) Long tenantId,
                              @RequestHeader(Constants.KEY_X_C3_PLATFORM) String platform,
                              @RequestHeader(Constants.KEY_X_C3_USERNAME) String username,
                              @RequestBody List<Long> stockIds);
}
